package com.demo.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.demo.model.User;

@Controller
@RequestMapping("/")
public class IndexController {

	Logger logger = Logger.getLogger(getClass());

	@RequestMapping("")
	@ResponseBody
	public Object index(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		logger.info("----index----");

		printHalvingLine();

		printHalvingLine();
		return new User();
	}

	// @RequestMapping("/hi")
	// public ModelAndView hi() {
	// printHalvingLine();
	// ModelAndView mav = new ModelAndView("hello");
	// mav.addObject("user", new User());
	// printHalvingLine();
	// return mav;
	// }

	@RequestMapping("/404")
	@ResponseBody
	public Object notFound(String json) {
		String msg = "page  not  found!";
		return this;
	}

	@RequestMapping("/500")
	@ResponseBody
	public Object sysError(String json) {
		String msg = "system error!";
		return msg;
	}

	public static void main(String[] args) {

	}

	static void printHalvingLine() {
		System.out.println("------------------------------");
		System.out.println("------------------------------");
	}
}
